# -*- coding: utf-8 -*-  
import utils
import time
from sklearn.cluster import KMeans

def load_pca_model(dim):
	model_arr=[]
	for j in range(10):
		model_file="models/pca_train_matrix_"+str(j)+"_"+str(dim)
		model_arr.append(utils.load_matrix(model_file))
	model=np.array(model_arr)
	return model

def kmeans(i,dim,clusters=2048):
	file="models/pca_train_matrix_"+str(i)+"_"+str(dim)
	samples=utils.load_matrix(file)
	init='k-means++'
	kmeans=KMeans(n_clusters=clusters,init=init,n_jobs=2)
	kmeans.fit(samples)
	centers=kmeans.cluster_centers_
	utils.save_matrix(centers,"models/kmeans_"+str(clusters)+"_train_matrix_"+str(i)+"_"+str(dim))

if __name__ == "__main__":
	t=time.time()
	dim=30
	clusters=512
	for i in range(10):
		kmeans(i,dim,clusters)
	t1=time.time()
	print (t1-t)